import request from "@/utils/request";
const defaultApi = (apiName) => {
    return {
        list: (params) => request.get(`/${apiName}/list`, { params }),
        tree: (params) => request.get(`/${apiName}/tree`, { params }),
        simpleList: (params) => request.get(`/${apiName}/simpleList`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    login: (data) => request.post('/user/login', data),
    menu: defaultApi('menu'),
    role: defaultApi('role'),
    user: {
        ...defaultApi('user'),
        getUserInfo: (userId) => request.get(`/user/getUserInfo`, { params: { userId }}),
        getUserRoles: (userId) => request.get(`/user/getUserRoles`, { params: { userId }}),
        updateUserRoles: (data) => request.post(`/user/updateUserRoles`, data),
    },
    member: defaultApi('memberUser'),
    banner: defaultApi('wxBanner'),
    category: defaultApi('wxMenu'),
    district: {
        ...defaultApi('district'),
        tree: (params) => request.get('/district/tree', { params })
    },
    officeBuilding: {
        ...defaultApi('officeBuilding'),
    },
    houseFollowup: {
        ...defaultApi('houseFollowup'),
    },
    officeBuildingTemplate: {
        ...defaultApi('officeBuildingTemplate'),
    },
    // Office shop related APIs
    officeCategory: {
        ...defaultApi('category'),
        tree: (params) => request.get('/category/tree', { params })
    },
    officeProduct: defaultApi('product'),
    officeOrder: {
        ...defaultApi('order'),
        ship: (data) => request.post('/order/ship', data),
        complete: (data) => request.post('/order/complete', data),
        cancel: (data) => request.post('/order/cancel', data),
        statistics: () => request.get('/order/statistics'),
        // WeChat payment endpoints
        createWxPayment: (data) => request.post('/order/createWxPayment', data),
        queryWxPayment: (orderId) => request.get('/order/queryWxPayment', { params: { id: orderId } }),
        refundOrder: (data) => request.post('/order/refundOrder', data),
        queryRefund: (refundId) => request.get('/order/queryRefund', { params: { id: refundId } }),
        listRefunds: (params) => request.get('/order/listRefunds', { params })
    },
    officeOrderRefund: {
        ...defaultApi('officeOrderRefund'),
        listByOrder: (orderId) => request.get('/officeOrderRefund/listByOrder', { params: { order_id: orderId } })
    }
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
